package com.ruoyi.tea.task;

import cc.casually.htmlParse.http.HttpClient;
import cc.casually.htmlParse.http.Request;
import cc.casually.htmlParse.http.Response;
import com.ruoyi.tea.cache.ConfCache;
import com.ruoyi.tea.conf.WxChatConf;

public class RefreshConfCacheTask {

    public void refreshAccessToken() {
        Request request = new Request();
        request.setUri("https://api.weixin.qq.com/cgi-bin/token");
        request.addParam("grant_type", "client_credential");
        request.addParam("appid", WxChatConf.APPID);
        request.addParam("secret", WxChatConf.SECRET);
        try {
            Response response = HttpClient.get(request);
            System.out.println(response.getBodyStr());
            if (response.getBodyJson().getString("access_token") != null) {
                ConfCache.ACCESS_TOKEN = response.getBodyJson().getString("access_token");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
